const state = {
  openPages: null
}
const action =  {
  getters: {
    openPages() {
      return new Promise((resolve, reject)=>{
        //先前已经发送过请求去过去了，直接返回
        if(state.openPages){
          resolve(state.openPages)
        }
        //发送请求去获取
        wx.$API["login/getOpenPageList"]()
          .then((res) => {
            action.setters.setOpenPages(res.data)
            resolve(res.data)
          })
          .catch((error) => {
            console.log(error, "error")
            wx.showToast({
              title: error,
              icon: "none",
              duration: 3000,
            })
            reject(error)
          })
      })
    }
  },
  setters: {
    setOpenPages(val) {
      state.openPages = val
    }
  }
}

export default action